package com.demo.maintenance.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtils {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static boolean isOnline(String time){
        long current = System.currentTimeMillis();
        try {
            Date date = sdf.parse(time);
            if (current - date.getTime() <= 5 * 60 * 1000
                    && current - date.getTime() >= 0) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static String format(Date time){
        if (time == null){
            return null;
        }
        return sdf.format(time);
    }

}
